﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Design;
using System.Windows.Forms.Design;

namespace WindowsFormsApplication1
{
   
    public partial class ColorControl : System.Windows.Forms.UserControl
    {

        private int icolor;
        [Category("Color Control")]
        [BrowsableAttribute(true)]
        public int Color
        {
           get { return icolor; }
            set { icolor = value % 3;
            setColorImage(value % 3);
            }
       }
        public delegate void ChangeColourHandler(int colour);
        public event ChangeColourHandler ChangeColourEvent;
        public  ColorControl()
        {            
            InitializeComponent();
            icolor = 0;
            setColorImage(icolor);
        }

        public ColorControl( int c)
        {
            InitializeComponent();
            icolor = c % 3;
            setColorImage(icolor);
        }
        private void ColorControl_Click(object sender, EventArgs e)
        {
            icolor = (icolor + 1) % 3;
            setColorImage(icolor);
            Console.WriteLine("collor reo");
        }
        private void setColorImage(int c)
        {
            switch (icolor)
            {
                case 0: pictureBox1.Image = Properties.Resources.clrG;
                   // Load("");
                    break;
                case 1: pictureBox1.Image = Properties.Resources.clrY;
                    // pictureBox1.Load("WindowsFormsApplication1.Properties.Resources.clrY.bmp");
                    break;
                case 2: pictureBox1.Image = Properties.Resources.clrR;
                    // pictureBox1.Load("WindowsFormsApplication1.Properties.Resources.clrR.bmp");
                    break;
            }
            if(ChangeColourEvent!=null)
                ChangeColourEvent(icolor);
        }
        public static Color getRGB(int col)
        {
            
            switch (col)
            {
                case 0: return System.Drawing.Color.Green; 
                case 1: return System.Drawing.Color.Yellow; 
                case 2: return System.Drawing.Color.Red;
            }
            return System.Drawing.Color.Beige;
        }

    }
}
